<template>
  <div class="nav-bar-item" @click="itemClick">
    <div :style="activeStyle">
      <slot name="item-icon"></slot>
    </div>
    <div class="text" :style="activeStyle">
      <slot name="item-text"></slot>
    </div>
  </div>
</template>
<script>
export default {
  name: "navBarItem",
  props: {
    path: String,
    activeColor: {
      type: String,
      default: "RoyalBlue",
    },
  },
  computed: {
    isActive() {
      return this.$route.path.indexOf(this.path) !== -1;
    },
    activeStyle() {
      return this.isActive ? { color: this.activeColor } : {};
    },
  },
  methods: {
    // 跳转子组件
    itemClick() {
      this.$router.push(this.path);
    },
  },
};
</script>
<style lang="less" scoped>
.nav-bar-item {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 0.625rem 1.25rem;
  .icon {
    font-size: 1.5625rem;
  }
  .text {
    font-size: 0.8125rem;
  }
}
</style>